package org.ping.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ping.Tool.NewsUtil;

import com.alibaba.fastjson.JSON;

/**
 * @author PING 用户获取新闻的servlet
 */
@WebServlet("/getnews")
public class NewsServlet extends HttpServlet {
	private static final long serialVersionUID = 3801983894535182822L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取客户端发送过来的页数
		int page = Integer.valueOf(req.getParameter("page"));
		//System.out.println(page);
		PrintWriter pw = resp.getWriter();
		//获取内容
		Map title = NewsUtil.getNewsUtil().getTitle(page);
		
		String jsonstr = JSON.toJSONString(title);
		pw.print(jsonstr);
		pw.flush();
		pw.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
